1 00:00:00,540 --> 00:00:01,640 Hello and welcome. 2 00:00:01,650 --> 00:00:09,260 In this video we are going to create the logic that or make the calculator work. 3 00:00:09,480 --> 00:00:16,080 So let's create a new file that we use to write arjan Us crypt code. 4 00:00:16,470 --> 00:00:18,200 So this is hastier mouse. 5 00:00:18,210 --> 00:00:22,900 I'm just going to click on the file option here and click on new file. 6 00:00:23,160 --> 00:00:31,560 And I'm going to save this file save that's inside the directory codes on calculator and save these 7 00:00:31,710 --> 00:00:33,970 as loan calculator. 8 00:00:34,230 --> 00:00:35,910 DOT. 9 00:00:36,450 --> 00:00:38,250 Yes. 10 00:00:38,400 --> 00:00:40,610 Make sure and the drop down. 11 00:00:40,650 --> 00:00:45,840 I am going to select javascript save. 12 00:00:45,960 --> 00:00:52,260 So any code that here now will be a jab ask crip could o key to the function. 13 00:00:52,270 --> 00:00:53,280 I'm going to create. 14 00:00:53,290 --> 00:01:00,270 I'm going to call it compute loan because I've already made references to it here inside my hastier 15 00:01:00,270 --> 00:01:01,710 male code. 16 00:01:01,710 --> 00:01:12,420 So are typing the word function to create a function do function space followed by the name of the function 17 00:01:12,870 --> 00:01:18,390 and the function is going to be called compute. 18 00:01:19,200 --> 00:01:26,370 Not is used Come all case which means the first letter is the word case and the first of the next word 19 00:01:26,400 --> 00:01:28,680 is upper case. 20 00:01:28,750 --> 00:01:39,040 Next I need to place parentheses and then curly braces and separate the curly braces in between the 21 00:01:39,240 --> 00:01:45,100 brace this is where will add the logic for the loan. 22 00:01:45,120 --> 00:01:46,150 The first thing I want to do. 23 00:01:46,160 --> 00:01:49,360 I'm going to add some variables. 24 00:01:49,530 --> 00:01:57,400 So let me run through the variables with you on line 3 quick to variable kord amount. 25 00:01:57,480 --> 00:02:04,470 This would be this would represent the amount of long that you want to borrow and set it to court documents 26 00:02:04,470 --> 00:02:06,460 or get eliminated. 27 00:02:07,160 --> 00:02:10,700 And past them the idea of Mt.. 28 00:02:10,770 --> 00:02:16,170 If you're wondering where I got this idea for values from is from the hastier melon side of things so 29 00:02:16,170 --> 00:02:18,700 here we've got on the court amount. 30 00:02:18,960 --> 00:02:21,830 So that's what I'm referring to here. 31 00:02:21,940 --> 00:02:31,410 They did deduct value basically refers to the value that you would input as the amount line for a variable 32 00:02:31,440 --> 00:02:37,170 caught interest on an offset that equals to the document. 33 00:02:37,200 --> 00:02:38,970 Get element back. 34 00:02:39,680 --> 00:02:41,580 And the idea is interests. 35 00:02:41,580 --> 00:02:48,260 What does your rate so whatever value we have the interest rate is going to grab that too. 36 00:02:48,290 --> 00:02:54,750 Again I go into my hatim millercoors see we've gotten a Deek award interest on that score ricked that's 37 00:02:54,750 --> 00:02:57,820 what is referring to like fire. 38 00:02:57,870 --> 00:03:01,080 Got a variable quad months in. 39 00:03:01,230 --> 00:03:03,340 This is equal to the document. 40 00:03:03,390 --> 00:03:08,110 Get eliminated by a T and the idea is months. 41 00:03:08,260 --> 00:03:16,540 Can we have any value that is entered for that value for that month or be attached to the variable. 42 00:03:16,650 --> 00:03:23,380 So if we come in a game we have quite an idea chord and once that's what he's referring to. 43 00:03:23,590 --> 00:03:26,930 Here we've got a variable called interest. 44 00:03:26,940 --> 00:03:34,020 So this is going to represent the actual interest so the interest on the loan is going to be the amount 45 00:03:34,290 --> 00:03:41,740 which is one variable times the interest on does rate time during one. 46 00:03:41,910 --> 00:03:51,480 Any time you have values surrounded by parenthetic values are computed first so it would do the interest 47 00:03:51,480 --> 00:03:52,470 rate times. 48 00:03:52,490 --> 00:03:58,490 Or Point 1 first before the deviation and the multiplication. 49 00:03:58,830 --> 00:04:08,730 Okay so the point 1 basically gives it a two decimal places so you'd have two decimals after the figure 50 00:04:10,200 --> 00:04:11,100 line 7. 51 00:04:11,100 --> 00:04:18,200 Here are quite a variable called payment and this variable is going to be caused to the amount we represent 52 00:04:18,210 --> 00:04:22,860 the monthly payment that the loan borrower have to pay. 53 00:04:22,870 --> 00:04:28,610 So is going to equal the amount divided by the months plus the interest. 54 00:04:28,950 --> 00:04:31,930 And then here we have tashkin Ditto fixed method bisley. 55 00:04:32,070 --> 00:04:40,140 This enables you to have two decimal places or two numbers after the decimal place. 56 00:04:40,140 --> 00:04:41,570 That's what that is for. 57 00:04:41,600 --> 00:04:52,830 Next we'll get into a line of code that will be a rep repress possible for putting commas on numbers 58 00:04:53,190 --> 00:04:54,840 for three digits. 59 00:04:54,840 --> 00:04:59,840 So if we look triggered value and then place a comma after every three digit. 60 00:05:00,180 --> 00:05:08,100 Someone to try and explain this line it as much as I can hear the pain men physically here is equal 61 00:05:08,250 --> 00:05:14,530 to the pain meant to string busways converting value to string. 62 00:05:14,730 --> 00:05:17,110 And then we replace it. 63 00:05:17,130 --> 00:05:20,660 This is going to convert it into money. 64 00:05:20,680 --> 00:05:26,660 Format's going to convert the font format into money and doing that using this replace method. 65 00:05:26,660 --> 00:05:32,920 And inside the replacement here we've got these values are trying to explain these as much as I can 66 00:05:32,950 --> 00:05:42,890 this slash be here basically is used to look within a word boundary. 67 00:05:43,060 --> 00:05:50,740 And what that means is that it can't be part of another type of work has come of a pattern. 68 00:05:50,820 --> 00:05:52,250 It has to look for. 69 00:05:52,380 --> 00:05:56,330 And then this here this question mark. 70 00:05:56,340 --> 00:06:07,490 Basically the question mark I'm equal to tells it to find what the group is looking for. 71 00:06:07,490 --> 00:06:16,050 For example it will look for issues in these last three here to look for three digits so it will look 72 00:06:16,050 --> 00:06:21,580 for any three digits in a row and then place a comma there. 73 00:06:22,290 --> 00:06:34,350 Plus this plus basically marks the three digits wrapped in parentheses to make sure that is treated 74 00:06:34,800 --> 00:06:40,600 as a block of three so basically helps to repeat the pattern. 75 00:06:40,620 --> 00:06:47,670 So he knows where to place the comma after every three digits I've added another block another line 76 00:06:47,670 --> 00:06:55,400 of call line line here line basically is going to be responsible for displaying the output. 77 00:06:55,400 --> 00:07:02,030 So he's going to say document using the documentor get them in a method method and we grab grabbing 78 00:07:02,040 --> 00:07:04,900 the idea which is this here. 79 00:07:04,920 --> 00:07:09,090 This idea here this page to talk to is going to grab that. 80 00:07:09,090 --> 00:07:16,860 This is where it all inject the result of the computer and loan repayment. 81 00:07:16,870 --> 00:07:25,680 So to grab that and it will replace that Deve the content of it with this dot in his email and the value 82 00:07:25,680 --> 00:07:28,650 of this in his tim is this here. 83 00:07:28,830 --> 00:07:33,790 So now I'll put inside the TV here. 84 00:07:33,800 --> 00:07:37,920 It will outport the word monthly payment. 85 00:07:38,040 --> 00:07:44,680 It would then give the value of the monthly payment which is going to be in dollars plus the payment. 86 00:07:44,850 --> 00:07:45,200 Okay. 87 00:07:45,210 --> 00:07:46,230 So that's where it's going to do. 88 00:07:46,230 --> 00:07:55,500 So I'm just going to save that file and save all up and I'll go into my direct freely which is this 89 00:07:55,940 --> 00:08:03,220 and just double click on the loan calculator or hastier mail to run the application. 90 00:08:03,220 --> 00:08:05,240 So let's quickly test it. 91 00:08:05,460 --> 00:08:05,940 Let's see. 92 00:08:05,940 --> 00:08:07,470 I want to borrow 10000. 93 00:08:07,470 --> 00:08:13,730 You can either input the value or you can use this to Anglosphere to move it forward. 94 00:08:13,740 --> 00:08:17,190 So I'm going to put in ten thousand. 95 00:08:17,670 --> 00:08:21,890 And let's say the interest rate on that is 10 percent. 96 00:08:21,900 --> 00:08:25,850 Let's say one borrowed out of 12 months. 97 00:08:25,920 --> 00:08:34,520 This is what I'm going to repay eproms want I want six point six seven so these values are changeable. 98 00:08:34,530 --> 00:08:39,600 So feel free to play around with the values to test the app. 99 00:08:39,620 --> 00:08:41,010 So that's basically it. 100 00:08:41,010 --> 00:08:46,540 And we've got the main functionality of the app work in the next lecture. 101 00:08:46,560 --> 00:08:51,880 I'm just going to add some success to make it look a bit nicer. 102 00:08:52,110 --> 00:08:53,610 So that's it for this lecture. 103 00:08:53,610 --> 00:08:55,110 Thank you for watching. 104 00:08:55,110 --> 00:08:56,020 Bye for now.